<?php

namespace app\job;

use app\result\TimeQueueResult;
use think\queue\Job;

class Task
{
    public function fire(Job $job, $data)
    {
        $rt = $this->doJob($data);
        if ($rt) {
            $job->delete();
            return true;
        }

        // 重试三次失败 todo...
        if ($job->attempts() == 3) {
            $job->delete();
            return false;
        }

        //执行失败10S后重试
        $job->release(10);


    }

    public function doJob($data)
    {
        $res = (new TimeQueueResult())->do_job($data['id'] ?? 0);
        bs_log($res, 'doJobRes', 'queue_diy_task.log');
        return true;
    }
}
